Skip to content

Support class versions#1418

Open
jvandort wants to merge 1 commit intoTNG:mainfrom
jvandort:jvandort/support-class-versions
Open

Support class versions#1418
jvandort wants to merge 1 commit intoTNG:mainfrom
jvandort:jvandort/support-class-versions

Conversation

@jvandort
Copy link
Copy Markdown

@jvandort jvandort commented Feb 4, 2025

Add the class version to JavaClass so rules can verify the class version

Fixes #423

Add the class version to JavaClass so rules can verify the class version
@jvandort
Copy link
Copy Markdown
Author

jvandort commented Feb 5, 2025

I followed the guidelines in the original issue, but was unsure about testing.

How would you advise testing this?

@hankem
Copy link
Copy Markdown
Member

hankem commented Feb 8, 2025

One option could be to commit compiled classes in src/test/resources to the repository.

@jvandort
Copy link
Copy Markdown
Author

Do you have an example test method/class I should follow the style/pattern of?

* @return The Java version
*/
public int getJavaVersion() {
return major - 44;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be a bit nitpicky:
Do you consider the version old java versions 1.0, 1.1, ... as 1, 1, 2?
https://javaalmanac.io/bytecode/versions/
Java 1.0 -> class file version 45.0 -> java version 1
Java 1.1 -> class file version 45.3 -> java version 1
Java 1.2 -> class file version 46.0 -> java version 2
...
starting from Java5 you calculation works perfectly fine, before that the numbering is already weird on java side.
Do we ignore this since these version are so ancient that we can't expect anyone to stumble over java classes compiled before java 5?
Since even Java 8 is currently dyng, this should be fine

@StefanGraeber
Copy link
Copy Markdown

A test would be really great for this, including the LTS versions starting from Java 8: 8, 11, 17, 21, 25
checking in compiled classes sounds as the most stable solution, but I'm not sure of how to add these classes to the scanned packages/classes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rule to restrict to specific bytecode java version

3 participants